<?php
require 'page.class.php';
session_start();

$username=$_SESSION['username'];
$connetc=mysql_connect("localhost","root","");
mysql_select_db("shenji",$connetc);
mysql_query("set names utf8");
$sql4="select * from user where username='$username'";

$result4=mysql_query($sql4);
$row4=mysql_num_rows($result4);


if($row4==0){
	echo "<script>alert('用户不存在，请重新登录！');top.location.href='./login.php'</script>";
}else{


	$sql2="select count(*) as amount from other_jiekou";
	$result2=mysql_query($sql2);
	$row2=mysql_fetch_array($result2);
	$count=$row2['amount'];//总条数
	$pagesize=10;//每页显示的条数
	if($count%$pagesize){
		$page=ceil($count/$pagesize);
	}else{
		$page=$count/$pagesize;
	}
	if(isset($_GET['currentpage'])){
		$currentpage=intval($_GET['currentpage']);
	}else{
		$currentpage=1;
	}
	$start=($currentpage-1)*$pagesize;
	$sql="select * from other_jiekou left join type on other_jiekou.typeid=type.typeid order by id desc limit $start,$pagesize";
	$result = mysql_query($sql);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/colResizable-1.6.min.js"></script>
<style>
      .tip{
		  width:600px;
		  height:350px;
	  }

</style>
<script type="text/javascript">
$(function(){
  $("table").colResizable();
});
$(document).ready(function(){
  $(".click").click(function(){
     $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
     $(".tip").fadeOut(200);
  });
});

   function shouzhong_name(){
	    var licesneid=$("#licesneid").val();
		  if(licesneid==null||licesneid.length==0){
			  $("#yz_name").show();
			  
		  }else{
			  $("#yz_name").hide();
		  }
		
   }
   
		function tijiao(){
		    var licesneid=$("#licesneid").val();
			if(licesneid==null||licesneid.length==0){
				alert("licesneid不能为空");
				return false;
			}
			
			return true;
			
	   }
 $(document).ready(function(){
	  
	  var username="<?php echo $_SESSION['username']; ?>";
	  if(username==null||username.length==0){		  
		 window.top.location.href="../login.php";
	  }
	  
  })	   
</script>

</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">接口配置</a></li>
    <li><a href="#">处理候选机器码</a></li>
    </ul>
    </div>
	
    <div class="rightinfo">
    
    <div class="tools">
    	<ul class="toolbar">
        <li onclick="tj_all()"><span><img src="images/t01.png" /></span>添加全部</li>
        <li style="border:none;"><!-- <a href="download3.php"><span>下载</span></a> -->
        	<form method="post" action="download3.php">		
        	<select name="typeid" style="width:86px;height:34px;border:1px solid #ccc;">
			<?php $downsql="select * from type"; $downresult=mysql_query($downsql); while($downrow=mysql_fetch_assoc($downresult)){?>
			<option value="<?php echo $downrow['typeid'] ?>"><?php echo $downrow['name'] ?>
			</option>
			<?php } ?>
			</select>
			<input style="border:1px solid #ccc;padding:6px 10px;border-radius:5px;" name="downsub" type="submit"value="下载">
			</form>

        </li>
        </ul>
    </div>
	
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input  type="checkbox" name="checkbox" onclick="selectAll(this)"/></th>
        <th>licesneid</th>
        <th>备注</th>
        <th>类型</th>
        <th>基本操作</th>
        </tr>
        </thead>
        <tbody>
		<?php
		while($row=mysql_fetch_array($result)){
		?>
		<tr>
        <td><input  type="checkbox" name="son_checkbox" value="<?php echo $row['id'];?>"/></td>
        <td><?php echo $row['licesneid'];?></td>
        <td><?php echo $row['beizhu'];?></td>
        <td><?php echo $row['name'];?></td>
        <td><a  onclick="tj('<?php echo $row['id'];?>');" class="tablelink" onmouseover="this.style.cursor='pointer'">添加</a>
        </td>
        </tr> 
		<?php
	     }
		?>
        </tbody>
    </table>
	
    <div class="pagin">
    	<?php 
    		pagelinks();
    	?>
    </div>
	
    <div class="tip">
	  <div class="tiptop"><span>添加机器码</span><a></a></div>
      <div class="formbody">
      <form method="post" action="insert_jiekou_commit.php">
	  <input size="20" type="hidden" name="id" id="id">
      <ul class="forminfo">
      <li><label>机器码</label><input  id="licesneid" name="licesneid" type="text" onblur="shouzhong_name();" class="dfinput" /><i id="yz_name" style="display:none">名称不能为空</i></li>
	  <li><label>备注</label><textarea id="beizhu" name="beizhu" style="width:325px;height:150px;" class="textinput"></textarea></li>
      <li><label>&nbsp;</label><input name="submit" type="submit" class="btn" value="确认保存" onclick="return tijiao();"/></li>
      </ul>
	  </form>
      </div>
      <!--
	  <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" />&nbsp;
      <input name="" type="button"  class="cancel" value="取消" />
      </div>
	  -->
    </div>
	
    </div>
    
    <script type="text/javascript">
	
    function selectAll(objs){
	    obj=document.getElementsByName('son_checkbox');
		for(var i=0;i<obj.length;i++){
			if(objs.checked){
				obj[i].checked=true;
			}else{
				obj[i].checked=false;
			}
			
		}
	}

	function tj_all(){
	      obj=document.getElementsByName('son_checkbox');
		  var arrayid=new Array();
		  for(var i=0;i<obj.length;i++){
			  if(obj[i].checked){
				 var value=obj[i].value;
				 arrayid.push(value);
			  }
		  }
	
		  if(arrayid.length==0){
			  alert("请选择所要添加的机器码");
		  }else{
			  
			  if(confirm("确定要添加所选择的机器码吗？")){
				  
				 $.post('select_jiekou2_id.php',{arrayid:arrayid},function(data){
				  window.location.reload();
			    });
				  
			  }else{
				  return false;
			  }
			  
		  }
		  
	}

	
  
	  
function tj(id){
	 $.post("select_jiekou2_id.php",{id:id},function(data){
		      if(data==1){
				   alert("添加成功,此条数据将移除");
				   	
			  }
			  if(data==0){
				   alert("添加失败,注意备注不能有重复");
			  }
			 
			  location.reload();
		})
	
}
	  
	</script>

</body>

</html>
